import React, { Component } from 'react'
import {connect} from "react-redux" // connect是一个高阶组件
class App extends Component {
  fn(){
      this.props.setName()
  }
  render() {
    console.log(this.props)
    return (
      <div>{this.props.name}
        <button onClick={this.fn.bind(this)}>修改名字</button>
      </div>
    )
  }
}
let mapStateToprops =(state)=>{ // 将仓库得数据传递到组件中
    console.log(state)
    return {
        ...state
    }
}
let mapDispatchToprops =(dispatch)=>{ // 用来触发action的
    // 只有action可以修改state，ation需要distach来触发
    return {
        setName(){
            dispatch({
                type:"setName",
                payload:"lisi"
            })
        }
    }
}
export default connect(mapStateToprops,mapDispatchToprops)(App)